package common

import (
	"gin-vue/model"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

var DB *gorm.DB

func InitDB() {
	dsn := "root:214224@tcp(127.0.0.1:3306)/test"
	//dsn := viper.GetString("datasource.mysql") + ":" + viper.GetString("datasource.password") + "@tcp(" + viper.GetString("datasource.host") + ":" + viper.GetString("datasource.port") + ")/" + viper.GetString("datasource.database")

	db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		return
	}

	db.AutoMigrate(&model.User{})
	DB = db

}

func GetDB() *gorm.DB {
	return DB
}
